package com.ss.android.mine;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.a.ABHelper;
import com.ss.android.account.Spipe;
import com.ss.android.account.b.OnAccountRefreshListener;
import com.ss.android.account.e.MuteQuickClickListener;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.app.c.ImageManager;
import com.ss.android.article.base.feature.d.a.a$a;
import com.ss.android.article.base.feature.splash.SplashAdActivity;
import com.ss.android.common.app.IComponent;
import com.ss.android.common.applog.AppLog;
import com.ss.android.common.dialog.AlertDialog;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.ui.view.SwitchButton;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.newmedia.BaseAppData;
import com.ss.android.newmedia.MediaAppData;
import com.ss.android.newmedia.NewMediaConstants;
import com.ss.android.newmedia.activity.FragmentActivity;
import com.ss.android.newmedia.activity.browser.BrowserActivity;
import com.ss.android.update.UpdateHelper;

import org.json.JSONObject;

public class BaseSettingActivity extends FragmentActivity implements OnAccountRefreshListener, a$a, BaseAppData.a, MediaAppData.h$b {
    private View A;
    private SwitchButton B;
    private SwitchButton C;
    private View D;
    private View E;
    private View F;
    private View G;
    private View H;
    private View I;
    private TextView J;
    private View K;
    private TextView L;
    private View M;
    private View N;
    private View O;
    private TextView P;
    private TextView Q;
    private TextView R;
    private TextView S;
    private ViewGroup T;
    private SwitchButton U;
    private View V;
    private String W;
    private boolean X;
    private boolean Y;
    private String Z;
    int a;
    private MuteQuickClickListener aa;
    private View.OnClickListener ab;
    private View.OnClickListener ac;
    private View.OnClickListener ad;
    int b;
    TextView c;
    protected boolean d;
    protected AppData e;
    Spipe f;
    com.ss.android.article.base.feature.d.a g;
    int h;
    long i;
    boolean j;
    DialogInterface.OnClickListener k;
    private static int[] l;
    private static int[] m;
    private static int[] n;
    private static int[] o;
    private TextView p;
    private TextView q;
    private TextView r;
    private TextView s;
    private TextView t;
    private int u;
    private String[] v;
    private String[] w;
    private String[] x;
    private String[] y;
    private int z;

    static {
        BaseSettingActivity.l = new int[]{1, 0, 2, 3};
        BaseSettingActivity.m = new int[]{1, 0, 2};
        BaseSettingActivity.n = new int[]{1, 0, 2};
        BaseSettingActivity.o = new int[]{2, 1, 0};
    }

    public BaseSettingActivity() {

        this.u = 1;
        this.a = 1;
        this.z = 1;
        this.b = 1;
        this.W = "1.0";
        this.d = false;
        this.X = false;
        this.Y = true;
        this.h = 0;
        this.i = 0;
        this.j = false;
        this.aa = new e(this);
        this.ab = new g(this);
        this.ac = new com.ss.android.mine.h(this);
        this.ad = new i(this);
        this.k = new com.ss.android.mine.j(this);
    }

    static boolean a(BaseSettingActivity arg4) {
        boolean v0;
        if (arg4.f != null) {
            if ((arg4.f.isLogin) && arg4.f.userId > 0) {
                v0 = false;
            } else {
                Spipe.a(((Activity) arg4), android.support.design.a.createJumpData("title_default", "social_other"));
                v0 = true;
            }
        } else {
            v0 = false;
        }

        return v0;
    }

    public final void a() {
        if (this.isViewValid()) {
            this.h();
        }
    }

    protected final void a(int arg4) {
        if (arg4 >= 0 && arg4 < 4) {
            if (arg4 == 0) {
                MobClickCombiner.onEvent(((Context) this), "more_tab", "font_small");
            } else if (arg4 == 1) {
                MobClickCombiner.onEvent(((Context) this), "more_tab", "font_middle");
            } else if (arg4 == 2) {
                MobClickCombiner.onEvent(((Context) this), "more_tab", "font_big");
            } else if (arg4 == 3) {
                MobClickCombiner.onEvent(((Context) this), "more_tab", "font_extra_large");
            }

            this.d = true;
            this.u = arg4;
            this.e.a(BaseSettingActivity.l[arg4]);
            this.i();
        }
    }

    public final void a(long arg2) {
        if (!this.isDestroyed() && this.p != null) {
            this.b(arg2);
        }
    }

    final void a(boolean arg3) {
        com.ss.android.newmedia.message.c.a().a(Boolean.valueOf(arg3));
        this.d = true;
        if (arg3) {
            MobClickCombiner.onEvent(((Context) this), "more_tab", "notify_on");
        } else {
            MobClickCombiner.onEvent(((Context) this), "more_tab", "notify_off");
        }
    }

    private void b(long arg12) {
        String v0_1;
        long v0 = 0;
        int v2 = Math.abs(System.currentTimeMillis() - this.e.aJ) > 300000 ? 1 : 0;
        if (v2 == 0) {
            arg12 = v0;
        }

        if (arg12 < v0) {
            v0_1 = " - ";
        } else if (arg12 >= 1048576) {
            v0_1 = String.format("%.2fMB", Float.valueOf((((float) arg12)) / 1048576f));
        } else if (arg12 >= 1024) {
            v0_1 = String.format("%.2fKB", Float.valueOf((((float) arg12)) / 1024f));
        } else {
            v0_1 = String.format("%dB", Long.valueOf(arg12));
        }

        this.p.setText(String.format(this.getString(com.ss.android.article.browser.R.string.cur_cache_size_fmt), v0_1));
    }

    public final void b() {
        if ((this.isViewValid()) && this.e != null) {
            this.e.aJ = System.currentTimeMillis();
            this.e.a(new ImageManager(((Context) this)));
        }
    }

    final void b(int arg6) {
        if (arg6 >= 0 && arg6 < 3) {
            if (arg6 == 0) {
                MobClickCombiner.onEvent(((Context) this), "more_tab", "list_comment_off");
            } else if (arg6 == 1) {
                MobClickCombiner.onEvent(((Context) this), "more_tab", "list_comment_friend");
            } else if (arg6 == 2) {
                MobClickCombiner.onEvent(((Context) this), "more_tab", "list_comment_all");
            }

            this.d = true;
            this.b = arg6;
            AppData v0 = this.e;
            int v1 = BaseSettingActivity.o[arg6];
            v0.cR.add("comment_mode");
            v0.mListCommentPref = v1;
            v0.cL = true;
            this.j();
        }
    }

    final String c() {
        String v0 = this.e == null || this.e.aC() == null ? null : this.e.aC()
                + "\nuid: " + Spipe.inst().userId
                + "\ndevice_id: " + AppLog.deviceId()
                + "\nuser_city: " + this.e.localCityName
                + "\ncurrent_city: " + this.e.currentCityName
                + "\nmanifest_version: " + this.e.getAppContext().getManifestVersion()
                + "\napi_version: " + this.e.getAppContext().getVersionCode();
        return v0;
    }

    final void c(int arg6) {
        if (arg6 >= 0 && arg6 < 3) {
            if (arg6 == 0) {
                MobClickCombiner.onEvent(((Context) this), "more_tab", "bandwidth_big");
            } else if (arg6 == 1) {
                MobClickCombiner.onEvent(((Context) this), "more_tab", "bandwidth_normal");
            } else if (arg6 == 2) {
                MobClickCombiner.onEvent(((Context) this), "more_tab", "bandwidth_small");
            }

            this.d = true;
            this.z = arg6;
            AppData v0 = this.e;
            int v1 = BaseSettingActivity.n[arg6];
            v0.cR.add("flow_mode");
            v0.mLoadImagePref = v1;
            v0.cL = true;
            this.k();
        }
    }

    final void d() {
        int v0 = this.z;
        AlertDialog.Builder v1 = com.ss.android.j.b.createDialogBuilder(((Context) this));
        if (this.e.getAbSettings().isLoadImage4G()) {
            v1.setTitle(com.ss.android.article.browser.R.string.uz);
        } else {
            v1.setTitle(com.ss.android.article.browser.R.string.uy);
        }

        v1.setSingleChoiceItems(com.ss.android.article.browser.R.array.r, v0, new n(this));
        v1.setCancelable(true);
        v1.setNegativeButton(com.ss.android.article.browser.R.string.cancel, null);
        v1.show();
    }

    final void d(int arg6) {
        if (arg6 >= 0 && arg6 < 3) {
            if (arg6 == 0) {
                MobClickCombiner.onEvent(((Context) this), "more_tab", "refresh_auto");
            } else if (arg6 == 1) {
                MobClickCombiner.onEvent(((Context) this), "more_tab", "refresh_wifi");
            } else if (arg6 == 2) {
                MobClickCombiner.onEvent(((Context) this), "more_tab", "refresh_manual");
            }

            this.d = true;
            this.a = arg6;
            AppData v0 = this.e;
            int v1 = BaseSettingActivity.m[arg6];
            v0.cR.add("refresh_mode");
            v0.mRefreshListPref = v1;
            v0.cL = true;
            this.l();
        }
    }

    public final void e() {
        this.h();
    }

    public static void f() {
    }

    private void g() {
        if (this.f == null || !this.f.isLogin || this.f.userId <= 0) {
            this.V.setVisibility(View.GONE);
        } else {
            this.V.setVisibility(View.VISIBLE);
        }
    }

    public int getDayBackgroundRes() {
        return com.ss.android.article.browser.R.color.ssxinmian3;
    }

    public int getLayout() {
        return com.ss.android.article.browser.R.layout.i6;
    }

    public int getNightBackgroundRes() {
        return com.ss.android.article.browser.R.color.sx;
    }

    private void h() {
        if (!this.isDestroyed()) {
            UpdateHelper v0 = UpdateHelper.getInstance();
            if (v0 != null && (v0.h())) {
                this.A.setVisibility(View.VISIBLE);
                return;
            }

            this.A.setVisibility(View.GONE);
        }
    }

    private void i() {
        this.q.setText(this.v[this.u]);
    }

    public void init() {
        int v9 = 4;
        int v8 = 3;
        int v7 = View.GONE;
        boolean v1 = true;
        super.init();
        this.e = AppData.getInstance();
        this.f = Spipe.inst();
        this.f.addOnAccountRefreshListener(((OnAccountRefreshListener) this));
        this.e.cl.add(this);
        this.e.cT.add(this);
        this.g = new com.ss.android.article.base.feature.d.a(((Context) this), ((IComponent) this), (this));
        Intent v0 = this.getIntent();
        if (v0 != null) {
            this.X = v0.getBooleanExtra("from_notification", false);
            this.Z = v0.getStringExtra("gd_ext_json");
        }

        this.Y = true;
        this.mTitleView.setText(com.ss.android.article.browser.R.string.a0b);
        this.Q = (TextView) this.findViewById(com.ss.android.article.browser.R.id.a_t);
        this.Q.setOnClickListener(new View.OnClickListener() {

            public final void onClick(View arg5) {
                MobClickCombiner.onEvent(BaseSettingActivity.this, "more_tab", "click_agreement");
                Intent v0 = new Intent(BaseSettingActivity.this, BrowserActivity.class);
                v0.setData(Uri.parse("http://web.toutiao.com/user_agreement/?hideAll=1"));
                v0.putExtra("use_swipe", true);
                v0.putExtra("title", BaseSettingActivity.this.getString(com.ss.android.article.browser.R.string.user_agreement_title));
                BaseSettingActivity.this.startActivity(v0);
            }
        });
        this.R = (TextView) this.findViewById(com.ss.android.article.browser.R.id.a_u);
        this.R.setOnClickListener(this.ab);
        this.S = this.mTitleBar.findViewById(com.ss.android.article.browser.R.id.right_text);
        this.S.setText(com.ss.android.article.browser.R.string.uv);
        this.S.setVisibility(View.VISIBLE);
        this.S.setOnClickListener(this.ad);
        this.c = (TextView) this.findViewById(com.ss.android.article.browser.R.id.a_v);
        this.W = this.e.getAppContext().getAppVersion();
        if (android.support.design.a.isTextEmpty(this.W)) {
            this.W = "1.0";
        }

        String v0_1 = this.e.aC();
        if (android.support.design.a.isTest(this.getApplicationContext())) {
            v0_1 = this.c();
            this.j = true;
        }

        this.c.setText(((CharSequence) v0_1));
        this.c.setOnClickListener(this.ac);
        this.L = (TextView) this.findViewById(com.ss.android.article.browser.R.id.a_b);
        TextView v3 = this.L;
        int v0_2 = ABHelper.a(this.e.getAppContext()).c ? com.ss.android.article.browser.R.string.ur : com.ss.android.article.browser.R.string.us;
        v3.setText(v0_2);
        this.K = this.findViewById(com.ss.android.article.browser.R.id.a_a);
        this.K.setOnClickListener(new com.ss.android.mine.l(this));
        this.p = (TextView) this.findViewById(com.ss.android.article.browser.R.id.a_c);
        this.findViewById(com.ss.android.article.browser.R.id.a_k);
        this.N = this.findViewById(com.ss.android.article.browser.R.id.a_j);
        this.N.setOnClickListener(new p(this));
        if (android.support.design.a.isTest(this.getApplicationContext())) {
            this.O = this.findViewById(com.ss.android.article.browser.R.id.a_o);
            this.O.setOnClickListener(new q(this));
            UIUtils.setVisibility(this.O, 0);
        }

        AppData v3_1 = this.e;
        String v4 = ((BaseAppData) v3_1).appContext.getChannel();
        String[] v5 = NewMediaConstants.aa;
        v0_2 = 0;
        while (true) {
            if (v0_2 >= v9) {
                if (((BaseAppData) v3_1).cw == 0 || ((BaseAppData) v3_1).cw == -1) {
                    v0_2 = 0;
                } else {
                    v0_2 = 1;
                }
            } else if (!v5[v0_2].equalsIgnoreCase(v4)) {
                ++v0_2;
                continue;
            } else {
                v0_2 = 0;
                break;
            }
        }

        if (v0_2 == 0) {
            this.N.setVisibility(v7);
        }

        this.A = this.findViewById(com.ss.android.article.browser.R.id.a_l);
        this.P = (TextView) this.findViewById(com.ss.android.article.browser.R.id.a_m);
        this.P.setText(this.W);
        this.D = this.findViewById(com.ss.android.article.browser.R.id.a9n);
        this.findViewById(com.ss.android.article.browser.R.id.a9o);
        this.D.setOnClickListener(new com.ss.android.mine.r(this));
        this.E = this.findViewById(com.ss.android.article.browser.R.id.a9r);
        this.B = (SwitchButton) this.findViewById(com.ss.android.article.browser.R.id.a9t);
        this.findViewById(com.ss.android.article.browser.R.id.a9s);
        this.B.setChecked(this.e.mBackRefresh);
        this.B.setOnCheckStateChangeListener(new s(this));
        if (!this.e.getAbSettings().isBackPressedRefreshEnableFromServer()) {
            this.E.setVisibility(v7);
        }

        this.T = (ViewGroup) this.findViewById(com.ss.android.article.browser.R.id.a9u);
        this.U = (SwitchButton) this.findViewById(com.ss.android.article.browser.R.id.a9w);
        this.findViewById(com.ss.android.article.browser.R.id.a9v);
        v0_2 = this.e.refreshButtonSettingEnabled == 1 ? 1 : 0;
        if (v0_2 == 0) {
            this.T.setVisibility(v7);
        } else {
            v0_2 = this.e.buttonRefreshSetByUser;
            if (v0_2 < 0) {
                v0_2 = 1;
            }

            SwitchButton v3_2 = this.U;
            if (v0_2 <= 0) {
                v1 = false;
            }

            v3_2.setChecked(v1);
            this.U.setOnCheckStateChangeListener(new t(this));
        }

        this.findViewById(com.ss.android.article.browser.R.id.a9y);
        this.F = this.findViewById(com.ss.android.article.browser.R.id.a9x);
        this.q = (TextView) this.findViewById(com.ss.android.article.browser.R.id.a9z);
        this.F.setOnClickListener(new u(this));
        this.v = this.getResources().getStringArray(com.ss.android.article.browser.R.array.n);
        v0_2 = this.e.mFontSizePref;
        if (v0_2 < 0 || v0_2 > v9) {
            v0_2 = 0;
        }

        this.u = BaseSettingActivity.l[v0_2];
        this.i();
        this.findViewById(com.ss.android.article.browser.R.id.a_4);
        this.G = this.findViewById(com.ss.android.article.browser.R.id.a_3);
        this.t = (TextView) this.findViewById(com.ss.android.article.browser.R.id.a_5);
        this.G.setOnClickListener(new v(this));
        try {
            if (!"lenovo".equals(this.e.getAppContext().getChannel())) {
            } else {
                this.G.setVisibility(View.GONE);
            }
        } catch (Exception v0_3) {
        }

        v0_2 = this.e.mListCommentPref;
        if (v0_2 < 0 || v0_2 > v8) {
            v0_2 = 0;
        }

        this.y = this.getResources().getStringArray(com.ss.android.article.browser.R.array.p);
        this.b = BaseSettingActivity.o[v0_2];
        this.j();
        this.findViewById(com.ss.android.article.browser.R.id.a_1);
        this.H = this.findViewById(com.ss.android.article.browser.R.id.a_0);
        this.r = (TextView) this.findViewById(com.ss.android.article.browser.R.id.a_2);
        this.H.setOnClickListener(new com.ss.android.mine.b(this));
        this.w = this.getResources().getStringArray(com.ss.android.article.browser.R.array.u);
        v0_2 = this.e.mRefreshListPref;
        if (v0_2 < 0 || v0_2 > v8) {
            v0_2 = 0;
        }

        this.a = BaseSettingActivity.m[v0_2];
        this.l();
        this.J = (TextView) this.findViewById(com.ss.android.article.browser.R.id.a_9);
        if (this.e.getAbSettings().isLoadImage4G()) {
            this.J.setText(com.ss.android.article.browser.R.string.uz);
        } else {
            this.J.setText(com.ss.android.article.browser.R.string.uy);
        }

        this.I = this.findViewById(com.ss.android.article.browser.R.id.a_8);
        this.s = (TextView) this.findViewById(com.ss.android.article.browser.R.id.a__);
        this.I.setOnClickListener(new com.ss.android.mine.c(this));
        this.x = this.getResources().getStringArray(com.ss.android.article.browser.R.array.r);
        v0_2 = this.e.mLoadImagePref;
        if (v0_2 < 0 || v0_2 > v8) {
            v0_2 = 0;
        }

        this.z = BaseSettingActivity.n[v0_2];
        this.k();
        this.getResources().getStringArray(com.ss.android.article.browser.R.array.q);
        this.M = this.findViewById(com.ss.android.article.browser.R.id.a_e);
        this.findViewById(com.ss.android.article.browser.R.id.a_f);
        this.C = (SwitchButton) this.findViewById(com.ss.android.article.browser.R.id.a_g);
        this.C.setChecked(com.ss.android.newmedia.message.c.a().h());
        this.C.setOnCheckStateChangeListener(new com.ss.android.mine.d(this));
        com.ss.android.newmedia.message.c.a();
        this.getApplicationContext();
        if (com.ss.android.newmedia.message.c.g()) {
            this.M.setVisibility(View.VISIBLE);
        } else {
            this.M.setVisibility(v7);
        }

        this.findViewById(com.ss.android.article.browser.R.id.a9m);
        this.findViewById(com.ss.android.article.browser.R.id.wk);
        this.findViewById(com.ss.android.article.browser.R.id.a_7);
        this.findViewById(com.ss.android.article.browser.R.id.wl);
        this.findViewById(com.ss.android.article.browser.R.id.a_i);
        this.findViewById(com.ss.android.article.browser.R.id.a9q);
        this.findViewById(com.ss.android.article.browser.R.id.a_6);
        this.findViewById(com.ss.android.article.browser.R.id.a_d);
        this.findViewById(com.ss.android.article.browser.R.id.a_h);
        this.findViewById(com.ss.android.article.browser.R.id.a_n);
        this.V = this.findViewById(com.ss.android.article.browser.R.id.a_q);
        this.V.setOnClickListener(this.aa);
        this.g();
    }

    private void j() {
        this.t.setText(this.y[this.b]);
    }

    private void k() {
        this.s.setText(this.x[this.z]);
    }

    private void l() {
        this.r.setText(this.w[this.a]);
    }

    public void onAccountRefresh(boolean arg1, int arg2) {
        this.g();
    }

    public void onBackPressed() {
        if (!this.isFinishing()) {
            Intent v0 = null;
            if (this.isTaskRoot()) {
                v0 = ToolUtils.getLaunchIntentForPackage(((Context) this), this.getPackageName());
            }

            this.finish();
            if (v0 == null) {
                return;
            }

            this.startActivity(v0);
        }
    }

    public void onDestroy() {
        super.onDestroy();
        if (this.e != null) {
            this.e.cl.remove(this);
            this.e.cT.remove(this);
        }

        if (this.f != null) {
            this.f.b(((OnAccountRefreshListener) this));
        }
    }

    void onFontSizeClick() {
        int v0 = this.u;
        AlertDialog.Builder v1 = com.ss.android.j.b.createDialogBuilder(((Context) this));
        v1.setTitle(com.ss.android.article.browser.R.string.uw);
        v1.setSingleChoiceItems(com.ss.android.article.browser.R.array.n, v0, new k(this));
        v1.setCancelable(true);
        v1.setNegativeButton(com.ss.android.article.browser.R.string.cancel, null);
        v1.show();
    }

    public void onPause() {
        super.onPause();
        if (!this.isDestroyed() && (this.d)) {
            this.d = false;
            this.e.d(false);
            this.e.g(((Context) this));
        }
    }

    public void onResume() {
        JSONObject v8;
        long v4 = 0;
        super.onResume();
        JSONObject v0 = null;
        if (!android.support.design.a.isTextEmpty(this.Z)) {
            try {
                v8 = new JSONObject(this.Z);
            } catch (Exception v1) {
                v8 = v0;
            }
        } else {
            v8 = v0;
        }


        MobClickCombiner.onEvent(this, "more_tab", "enter", v4, v4, v8);
        this.h();
        if (!this.isDestroyed() && this.p != null) {
            if (this.e.cj) {
                this.b(this.e.aF());
            } else {
                this.b(-1);
            }
        }

        boolean v0_1 = !this.Y || !this.X ? false : true;
        SplashAdActivity.a(((Context) this), v0_1);
        this.Y = false;
    }
}

